<template>
  <!-- 工作票关闭 -->
  <a-modal
    v-model:open="visible"
    title="工作票关闭"
    @ok="handleOk"
    class="addStation"
    destroyOnClose
    :width="430"
    @cancel="cancel"
    centered
  >
    <a-form
      :model="form"
      :rules="rules"
      layout="inline"
      :labelCol="labelCol"
      ref="formRef"
    >
      <a-form-item label="备注" name="approveDesc">
        <a-textarea
          v-model:value="form.approveDesc"
          class="formInput"
          placeholder="请输入"
          type="textarea"
          allow-clear
          :rows="3"
        />
      </a-form-item>
    </a-form>
    <template #footer>
      <div class="footerBar">
        <a-button key="back" @click="cancel">取消</a-button>
        <a-button
          key="submit"
          type="primary"
          :loading="loading"
          @click="handleSubmit"
          >确认</a-button
        >
      </div>
    </template>
  </a-modal>
</template>
<script setup>


import storage from "@/utils/storage";
const $api = inject("$api");
const props = defineProps({
  ticketCloseVisible: {
    type: Boolean,
    default: false,
  },
  rowData: {
    type: Object,
  },
  stationtList: {
    type: Array,
  },
});
const visible = ref(props.ticketCloseVisible);
const emits = defineEmits(["update:ticketCloseVisible", "getOrderList"]);
watch(
  () => props.ticketCloseVisible,
  async (val) => {
    visible.value = val;
  }
);
const form = ref({
  approveDesc: undefined,
});
const formRef = ref();
const rules = {
  approveDesc: [
    {
      required: true,
      message: "请输入备注",
      trigger: "blur",
    },
  ],
};
const cancel = () => {
  emits("update:ticketCloseVisible", false);
  formRef.value.clearValidate();
  form.value = {
    reason: undefined,
  };
};
const loading = ref(false);
const handleSubmit = () => {
  formRef.value
    .validate()
    .then(async () => {
      const params = {
        ...form.value,
        id: props.rowData.id,
      };
      loading.value = true;
      const res = await $api.ticketClose(params);
      loading.value = false;
      if (res && res.code === 0) {
        message.success("关闭成功");
        cancel();
        emits("getOrderList");
      }
    })
    .catch((error) => {
      console.log("error", error);
    });
};
</script>

<style lang="less" scoped>
.form {
  padding: 0 40px;
  margin-top: 30px;
}
.formInput,
.formSelect {
  width: 300px;
}
.ant-form-item {
  margin-top: 20px;
}
.footerBar {
  text-align: center;
  margin-top: 30px;
}
</style>